package service;

import com.fr.script.AbstractFunction;
import com.wondersgroup.hs.mobile.nursing.rpc.utils.ClientServiceFactory;
import com.wondersgroup.hs.report.plugin.utils.GlobalParameterUtils;
import util.ReportError;

import java.net.MalformedURLException;
import java.net.URL;

/**
 * Created by zarra on 2017/5/17.
 */
public abstract class RestServiceFunction extends AbstractFunction {

    public <S> S restService(Class<S> sClass){
        String value = GlobalParameterUtils.getGlobalParameter("ReportServiceURL");
        if (value!=null){
            try {
                return ClientServiceFactory.service(sClass, new URL(value));
            } catch (MalformedURLException e) {
                throw new ReportError(e);
            }
        }
        throw new NullPointerException();

    }


}
